package com.zhiyun.common;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

/**
 * 带图标列表对话框的适配器
 * 
 * @author teddy
 * 
 */
public class DialogItemListAdapter extends ArrayAdapter<DialogItem> {

	public DialogItemListAdapter(Context context, List<DialogItem> objects) {
		super(context, android.R.layout.select_dialog_item, android.R.id.text1,
				objects);
	}

	public View getView(int position, View convertView, ViewGroup parent) {

		View v = super.getView(position, convertView, parent);
		TextView tv = (TextView) v.findViewById(android.R.id.text1);

		if (this.getItem(position).icon != -1) {
			tv.setCompoundDrawablesWithIntrinsicBounds(
					this.getItem(position).icon, 0, 0, 0);
			int dp5 = (int) (5 * this.getContext().getResources()
					.getDisplayMetrics().density + 0.5f);
			tv.setCompoundDrawablePadding(dp5);
		}

		return v;
	}

}
